package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.CoordinateDto;
import com.hualude.roadsign.model.CoordinateEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;


/**
 * Created by xu_jiaHui on 2017/8/17.
 */
public interface CoordinateRepository extends CrudRepository<CoordinateEntity, Long> {


    /**
     * @Description:
     * @author xu_jiaHui
     * @date 2017/8/18 14:47
     */
    @Modifying
    @Query(value = "delete from CoordinateEntity where coordinateTypeId=?1 and coordinateType=?2")
    public Integer deleteCoordinateByTypeId(Integer typeId, Integer type) throws Exception;

    @Query(value = "select new com.hualude.roadsign.dto.CoordinateDto(coordinateLongitude,coordinateLatitude) " +
            "from CoordinateEntity where coordinateTypeId=?1 and coordinateType=?2 order by coordinateOrder")
    public List<CoordinateDto> getCoordinatesById(Integer roadLineId, Integer type) throws Exception;
}
